
// ##############################
// ####  note:  bokeweilai bk doorbell main fun
// ####  create:  TANWENHUI (twh:谭文辉)
// ####  date:   2024/6/18
// ##############################

#ifndef __BKWL_BK_DOORBELL_MAIN_H__
#define __BKWL_BK_DOORBELL_MAIN_H__
#include "bk_private/bk_init.h"
#include <components/system.h>
#include <os/os.h>
#include <components/shell_task.h>
#include "cli.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include "pthread.h"
#include <components/event.h>
#include <components/netif.h>
#include "dev_log.h"
#include "../../../../../../bk_idk/components/bk_bluetooth/bt/ble_boarding/ble_boarding.h"

#define TRANSMISSION_BIG_ENDIAN (BK_FALSE)

#if TRANSMISSION_BIG_ENDIAN == BK_TRUE
#define CHECK_ENDIAN_UINT32(var) htonl(var)
#define CHECK_ENDIAN_UINT16(var) htons(var)

#define STREAM_TO_UINT16(u16, p)                                        \
    {                                                                   \
        u16 = (((uint16_t)(*((p) + 1))) + (((uint16_t)(*((p)))) << 8)); \
        (p) += 2;                                                       \
    }
#define STREAM_TO_UINT32(u32, p)                                                                                                                      \
    {                                                                                                                                                 \
        u32 = ((((uint32_t)(*((p) + 3)))) + ((((uint32_t)(*((p) + 2)))) << 8) + ((((uint32_t)(*((p) + 1)))) << 16) + ((((uint32_t)(*((p))))) << 24)); \
        (p) += 4;                                                                                                                                     \
    }

#else
#define CHECK_ENDIAN_UINT32
#define CHECK_ENDIAN_UINT16

#define STREAM_TO_UINT16(u16, p)                                    \
    {                                                               \
        u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \
        (p) += 2;                                                   \
    }
#define STREAM_TO_UINT32(u32, p)                                                                                                                  \
    {                                                                                                                                             \
        u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); \
        (p) += 4;                                                                                                                                 \
    }

#endif

#define STREAM_TO_UINT8(u8, p) \
    {                          \
        u8 = (uint8_t)(*(p));  \
        (p) += 1;              \
    }

#define AV_CLIENT_SEND_MAX_RETRY (2000)
#define AV_CLIENT_SEND_MAX_DELAY (20)

// typedef void (*ble_boarding_op_cb_t)(uint16_t opcode, uint16_t length, uint8_t *data);
// #if CONFIG_AT
// int dm_ble_boarding_handle(int sync, int argc, char **argv);
// #elif defined(CONFIG_AT_CMD)
// int dm_ble_boarding_handle(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv);
// #endif

// typedef struct
// {
//     char *ssid_value;
//     char *password_value;
//     ble_boarding_op_cb_t cb;
//     uint8_t boarding_notify[2];
//     uint16_t ssid_length;
//     uint16_t password_length;
// } ble_boarding_info_t;

typedef struct
{
    ble_boarding_info_t boarding_info;
    uint16_t channel;
} doorbell_boarding_info_t;

#endif
